package com.toycloud.business.controller.business;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.toycloud.business.dto.params.business.AssociationDemandParams;
import com.toycloud.business.dto.params.business.FeedbackApplicationVersionManagerParams;
import com.toycloud.business.dto.results.CommonResult;
import com.toycloud.common.core.utils.poi.ExcelUtil;
import com.toycloud.common.core.controller.BaseController;
import com.toycloud.common.core.utils.poi.RuoyiExcelUtil;
import com.toycloud.common.core.web.domain.AjaxResult;
import com.toycloud.system.domain.business.FeedbackApplicationVersionManager;
import com.toycloud.system.log.annotation.Log;
import com.toycloud.system.log.enums.BusinessType;
import com.toycloud.system.mapper.business.FeedbackApplicationVersionManagerMapper;
import com.toycloud.system.service.business.IFeedbackApplicationVersionManagerDetailService;
import com.toycloud.system.service.business.IFeedbackApplicationVersionManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 应用版本管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/appmanager")
public class FeedbackApplicationVersionManagerController extends BaseController
{
    @Autowired
    private IFeedbackApplicationVersionManagerService feedbackApplicationVersionManagerService;
    @Autowired
    private IFeedbackApplicationVersionManagerDetailService feedbackApplicationVersionManagerDetailService;
    @Resource
    private FeedbackApplicationVersionManagerMapper feedbackApplicationVersionManagerMapper;

    /**
     * 查询应用版本管理列表
     */
    @PostMapping("/page")
    public CommonResult<List<FeedbackApplicationVersionManager>> list(@RequestBody FeedbackApplicationVersionManagerParams feedbackApplicationVersionManagerParams)
    {
        return feedbackApplicationVersionManagerService.selectFeedbackApplicationVersionManagerList(feedbackApplicationVersionManagerParams);
    }
    @GetMapping("/list")
    public AjaxResult getList()
    {
        return AjaxResult.success(feedbackApplicationVersionManagerService.getList());
    }

    @GetMapping("/option")
    public AjaxResult option()
    {
        return AjaxResult.success(feedbackApplicationVersionManagerService.option());
    }

    /**
     * 导出应用版本管理列表
     */
    @Log(title = "应用版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody FeedbackApplicationVersionManagerParams feedbackApplicationVersionManagerParams)
    {
        CommonResult<List<FeedbackApplicationVersionManager>> list = feedbackApplicationVersionManagerService.export(feedbackApplicationVersionManagerParams);
        ExcelUtil<FeedbackApplicationVersionManager> util = new ExcelUtil<FeedbackApplicationVersionManager>(FeedbackApplicationVersionManager.class);
        util.exportExcel(response, list.getData(), "应用版本管理数据");
    }
    @PostMapping("/export2")
    public void export2(@RequestBody FeedbackApplicationVersionManagerParams feedbackApplicationVersionManagerParams, HttpServletResponse response) {
        CommonResult<List<FeedbackApplicationVersionManager>> list = feedbackApplicationVersionManagerService.selectFeedbackApplicationVersionManagerList(feedbackApplicationVersionManagerParams);
        RuoyiExcelUtil.exportExcel(list.getData(), "应用版本管理数据", FeedbackApplicationVersionManager.class, response);
    }
/**
 * @Auther: doubaolin
 * @Date: 2024/12/18 15:47
 * @Description: 新增应用版本管理
 * @param
 * @return:
 */
    @PostMapping("/add")
    public CommonResult add(@Valid @RequestBody FeedbackApplicationVersionManager feedbackApplicationVersionManager)
    {
        return feedbackApplicationVersionManagerService.insertFeedbackApplicationVersionManager(feedbackApplicationVersionManager);
    }
    @PostMapping("/update")
    public CommonResult update(@Valid @RequestBody FeedbackApplicationVersionManager feedbackApplicationVersionManager)
    {
        return feedbackApplicationVersionManagerService.updateFeedbackApplicationVersionManager(feedbackApplicationVersionManager);
    }
/**
 * @Auther: doubaolin
 * @Date: 2024/12/18 15:48
 * @Description: 查询新增应用版本管理的应用字段下拉
 * @param
 * @return:
 */
    @GetMapping("/selectApplicationOption")
    public AjaxResult selectApplicationOption()
    {
        return AjaxResult.success(feedbackApplicationVersionManagerService.selectApplicationOption());
    }

/**
 * @Auther: doubaolin
 * @Date: 2024/12/19 10:38
 * @Description: 关联需求选择列表
 * @param
 * @return:
 */
    @GetMapping("/getDemandPage")
    public CommonResult<List<AssociationDemandParams>> getDemandPage(AssociationDemandParams associationDemandParams)
    {
        return feedbackApplicationVersionManagerService.getDemandPage(associationDemandParams);
    }
    /**
     * @Auther: doubaolin
     * @Date: 2024/12/19 14:07
     * @Description: 删除主表+子表
     * @param
     * @return:
     */
    @PostMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable String id)
    {
        feedbackApplicationVersionManagerService.deleteFeedbackApplicationVersionManagerById(id);
        feedbackApplicationVersionManagerDetailService.deleteFeedbackApplicationVersionManagerDetailByParentId(id);
        return AjaxResult.success("删除成功");
    }
    @GetMapping("/{id}")
    public AjaxResult getDemandRecord(@PathVariable String id)
    {
        return AjaxResult.success(feedbackApplicationVersionManagerService.selectFeedbackApplicationVersionManagerById(id));
    }
    /**
     * @Auther: doubaolin
     * @Date: 2024/12/23 17:52
     * @Description: 查询框的树形结构
     * @param
     * @return:
     */
    @GetMapping("/getTree")
    public AjaxResult getTree() {
        return feedbackApplicationVersionManagerService.getTree();
    }

    @GetMapping("/getAppAndVersionTree")
    public AjaxResult getAppAndVersionTree() {
        return feedbackApplicationVersionManagerService.getAppAndVersionTree();
    }
}
